﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HMIS.FrameWork.DomainBase;
using HMIS.FrameWork;

namespace HMIS.Site.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }
        //Json输出试一试
        public ActionResult test5()
        {
            return Json(new { 
                Name = "弦哥", 
                Age = 26, 
                IsMarry = true,
                MyDog = new { Name = "大海", Age = 1, Variety="罗威纳" }
            });//小菜注意一下，这个写法叫匿名对象c#3.0新加的...
        }
        //测试一下
        public ActionResult test()
        {
            HMIS.Infrastructure.Core.Repositories.IDictionaryRepository r = new HMIS.Infrastructure.Core.Repositories.Impl.DictionaryRepositoryImpl();
            long total;
            var list = r.GetPlistByCategoryId("48391bb4-471b-4499-899b-cea9748e1a7b", 0, 15, "Index", "desc", null, out total);

            //我们自己的Json序列化方法
            return this.JsonFormat(
                list,
                new string[] { "Category" });//指定需要序列化属性“Category”
        }
        //测试一下
        public ActionResult test3()
        {
            HMIS.Infrastructure.Core.Repositories.IDictionaryRepository r = new HMIS.Infrastructure.Core.Repositories.Impl.DictionaryRepositoryImpl();
            long total;
            var list = r.GetPlistByCategoryId("48391bb4-471b-4499-899b-cea9748e1a7b", 0, 15, "Index", "desc", null, out total);
            string str;
            foreach (var item in list)
            {
                str = item.Category.Name;//如果你不用fetch 每一次循环我都会去访问数据库，哈哈
            }
            return Content("");
        }

        public ActionResult test2()
        {
            var dfList = new List<DataFilter>();
            dfList.Add(new DataFilter { field = "Name", type = "string", value = "张" });
            dfList.Add(new DataFilter { field = "Age", type = "numeric", value = "20", comparison = "gt" });
            dfList.Add(new DataFilter { field = "Age", type = "numeric", value = "30", comparison = "lt" });
            dfList.Add(new DataFilter { field = "IsMarry", type = "boolean", value = "false" });
            var r = new HMIS.FrameWork.Repository.Nhb.RepositoryNhbImpl<BaseEntity>().GetHqlstrByExtFilter(dfList, "o");
            return Content(r);
        }
    }
}
